import java.util.concurrent.*;

public class Demo1 {
    public volatile static int COUNT;

    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(1, 2, 1000, TimeUnit.MILLISECONDS,
                new SynchronousQueue<Runnable>(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 3; i++) {
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello");
                }
            });
        }

    }
    public static void main1(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(2);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                try {
                    semaphore.acquire();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                for (int i = 0; i < 50000; i++) {
                    COUNT++;
                }
                semaphore.release();
            }
        };

        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(COUNT);


    }
}


